<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<?php include APPLICATION_PATH . '/modules/default/layouts/scripts/content-outer-start.phtml'; ?>
<script type="text/javascript">
    /*
    Number.prototype.formatNumber = function(c, d, t){
        var n = this,
        c = isNaN(c = Math.abs(c)) ? 2 : c,
        d = d === undefined ? "." : d,
        t = t === undefined ? "," : t,
        s = n < 0 ? "-" : "",
        i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
        j = (j = i.length) > 3 ? j % 3 : 0;
       return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
     };
     */
    function viewInfoDaily(idDL) {
        var code_daily = idDL;
        $.ajax({
            url: '<?php echo $this->baseUrl ?>/default/tracuutongquat/getinfodaily',
            type: "POST",
            data: {
                code_daily: code_daily
            },
            dataType: "json",
            success: function(resultData) {
                if (resultData.ErrorCode !== "-1") {
                    var tenDL = resultData.tenDL;
                    $("#nameDL").html(tenDL);
                    
                    //var tongLoiNhuan = resultData.tongLoiNhuan;
                    //tongLoiNhuan = tongLoiNhuan.formatNumber(2, '.', ',');
                    //$("#sumLN").html(tongLoiNhuan);
                    
                    //var loiNhuanTinhLai = resultData.loiNhuanTinhLai;
                    //loiNhuanTinhLai = loiNhuanTinhLai.formatNumber(2, '.', ',');
                    //$("#sumLNTL").html(loiNhuanTinhLai);
                    
                    var content1 = "";
                    content1 += '<tr class="GridHeader" align="center">'
                                    + '<th align="center" scope="col">STT</th>'
                                    + '<th align="center" scope="col">Đại lý bán</th>'
                                    + '<th align="center" scope="col">Đại lý mua</th>'
                                    + '<th align="center" scope="col">Tên sản phẩm</th>'
                                    + '<th align="center" scope="col">Đơn giá</th>'
                                    + '<th align="center" scope="col">Số lượng</th>'
                                    + '<th align="center" scope="col">Thuế(%)</th>'
                                    + '<th align="center" scope="col">Ngày bán</th>'
                                    + '<th align="center" scope="col">Thành tiền</th>'
                                    + '<th align="center" scope="col">Lợi nhuận</th>'
                                + '</tr>';
                    for (var i = 0; i < resultData.tableDHTB.length; i++) {
                        content1 += '<tr class="GridItem" align="center">'
                                 +   '<th align="center" scope="col">' + (i+1) + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHTB[i]['nameDLBan']    + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHTB[i]['nameDLMua']    + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHTB[i]['nameSP']       + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHTB[i]['donGia']       + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHTB[i]['soLuong']      + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHTB[i]['thue']         + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHTB[i]['ngayBan']      + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHTB[i]['thanhTien']    + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHTB[i]['loiNhuan']     + '</th>'
                                 +'</tr>';
                    }
                    $("#tableDHTB").html(content1);
                    
                    var content2 = "";
                    content2 += '<tr class="GridHeader" align="center">'
                                    + '<th align="center" scope="col">STT</th>'
                                    + '<th align="center" scope="col">Đại lý bán</th>'
                                    + '<th align="center" scope="col">Đại lý mua</th>'
                                    + '<th align="center" scope="col">Tên sản phẩm</th>'
                                    + '<th align="center" scope="col">Đơn giá</th>'
                                    + '<th align="center" scope="col">Số lượng</th>'
                                    + '<th align="center" scope="col">Thuế(%)</th>'
                                    + '<th align="center" scope="col">Ngày bán</th>'
                                    + '<th align="center" scope="col">Thành tiền</th>'
                                    + '<th align="center" scope="col">Lợi nhuận</th>'
                                + '</tr>';
                    for (var i = 0; i < resultData.tableDHCC.length; i++) {
                        content2 += '<tr class="GridItem" align="center">'
                                 +   '<th align="center" scope="col">' + (i+1) + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHCC[i]['nameDLBan']    + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHCC[i]['nameDLMua']    + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHCC[i]['nameSP']       + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHCC[i]['donGia']       + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHCC[i]['soLuong']      + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHCC[i]['thue']         + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHCC[i]['ngayBan']      + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHCC[i]['thanhTien']    + '</th>'
                                 +   '<th align="center" scope="col">' + resultData.tableDHCC[i]['loiNhuan']     + '</th>'
                                 +'</tr>';
                    }
                    $("#tableDHCC").html(content2);
                    
                } else{
                    alert("call Ajax Fail...");
                }
            }
        });

    }
    $(document).ready(function() {
        
    });
</script>
<div id="swaper">
    <div id="swap_left" align="left" style="float: left; width: 300px; height: 500px; overflow: scroll; border: #EBEBEB thin;">
        <h1 style="margin-top: 10px; margin-bottom: 5px;">Sơ đồ tổ chức</h1>
        <?php
        $rootAttributes = array("MaDaiLy"=>"0", "depth"=>"2");
        $treeID = "treev1";
        $tv = DBTreeView::createTreeView($rootAttributes, '../lib/dbtreeview', $treeID);
        $tv->setRootHTMLText("STEMPOWER");
        $tv->setRootIcon("../lib/dbtreeview/media/star.gif");
        $tv->printTreeViewScript();
        ?>
    </div>
    <div id="swap_right" style="float: right; width: 860px; height: auto;" align="center">
        <h2 style="margin-top: 5px;">Thông tin đại lý: <span id="nameDL">STEMPOWER</span></h2>
        <br/><br/>
        <h3 style="margin-top: 5px;">Tổng lợi nhuận tháng <?php echo date("m/Y");?>: <span id="sumLN"><?php echo number_format($this->dataTDH['LoiNhuan'], 0, '.', ','); ?></span> đồng</h3>
        <br/><br/>
        <h3>Thông tin đơn hàng tự bán</h3>
        <br/><br/>
        <!--pre><?php print_r($this->dataTDH) ?></pre-->
        <!--pre><?php print_r($this->arrDHTB) ?></pre-->
        <!--pre><?php print_r($this->arrDHCC) ?></pre-->
        <!--pre><?php print_r($this->tableDataDHTB) ?></pre-->
        <form id="mainform" action="#" method="post">
            <div class="form_row">
                <table class="Grid" cellspacing="0" cellpadding="3" rules="all" border="1" id="tableData" style="width:100%;border-collapse:collapse;">
                    <tbody id="tableDHTB">
                        <tr class="GridHeader" align="center">
                            <th align="center" scope="col">STT</th>
                            <th align="center" scope="col">Đại lý bán</th>
                            <th align="center" scope="col">Đại lý mua</th>
                            <th align="center" scope="col">Tên sản phẩm</th>
                            <th align="center" scope="col">Đơn giá</th>
                            <th align="center" scope="col">Số lượng</th>
                            <th align="center" scope="col">Thuế(%)</th>
                            <th align="center" scope="col">Ngày bán</th>
                            <th align="center" scope="col">Thành tiền</th>
                            <th align="center" scope="col">Lợi nhuận</th>
                        </tr>
                        <?php
                        if ($this->tableDataDHTB) {
                            $i=1;
                            foreach ($this->tableDataDHTB as $row) {
                        ?>
                                <tr class="GridItem" align="center">
                                    <th align="center" scope="col"><?php echo $i;?></th>
                                    <th align="center" scope="col"><?php echo $row['nameDLBan'];?></th>
                                    <th align="center" scope="col"><?php echo $row['nameDLMua'];?></th>
                                    <th align="center" scope="col"><?php echo $row['nameSP'];?></th>
                                    <th align="center" scope="col"><?php echo $row['donGia'];?></th>
                                    <th align="center" scope="col"><?php echo $row['soLuong'];?></th>
                                    <th align="center" scope="col"><?php echo $row['thue'];?></th>
                                    <th align="center" scope="col"><?php echo $row['ngayBan'];?></th>
                                    <th align="center" scope="col"><?php echo $row['thanhTien'];?></th>
                                    <th align="center" scope="col"><?php echo $row['loiNhuan'];?></th>
                                </tr>
                        <?php
                                $i = $i + 1;
                            }
                        } else{
                        ?>
                            <tr class="GridItem" align="center">
                                <th align="center" scope="col" colspan="10">Không có đơn hàng nào.</th>
                            </tr>
                        <?php
                        }
                        ?>
                    </tbody>
                </table>
            </div>
            <input type="hidden" name="codeDL" id="codeDL" value=""/>
        </form>
        
        <br/><br/><br/><br/>
        <div class="form_row" style="margin-top: 10px; margin-bottom: 10px;">
            <h3 style="margin-top: 5px;">Thông tin đơn hàng đại lý con</h3>
        </div>
        <br/><br/>
        <div class="form_row">
            <table class="Grid" cellspacing="0" cellpadding="3" rules="all" border="1" id="tableData" style="width:100%;border-collapse:collapse;">
                <tbody id="tableDHCC">
                    <tr class="GridHeader" align="center">
                        <th align="center" scope="col">STT</th>
                        <th align="center" scope="col">Đại lý bán</th>
                        <th align="center" scope="col">Đại lý mua</th>
                        <th align="center" scope="col">Tên sản phẩm</th>
                        <th align="center" scope="col">Đơn giá</th>
                        <th align="center" scope="col">Số lượng</th>
                        <th align="center" scope="col">Thuế(%)</th>
                        <th align="center" scope="col">Ngày bán</th>
                        <th align="center" scope="col">Thành tiền</th>
                        <th align="center" scope="col">Lợi nhuận</th>
                    </tr>
                    <?php
                    if ($this->tableDataDHCC) {
                        $i=1;
                        foreach ($this->tableDataDHCC as $row) {
                    ?>
                            <tr class="GridItem" align="center">
                                <th align="center" scope="col"><?php echo $i;?></th>
                                <th align="center" scope="col"><?php echo $row['nameDLBan'];?></th>
                                <th align="center" scope="col"><?php echo $row['nameDLMua'];?></th>
                                <th align="center" scope="col"><?php echo $row['nameSP'];?></th>
                                <th align="center" scope="col"><?php echo $row['donGia'];?></th>
                                <th align="center" scope="col"><?php echo $row['soLuong'];?></th>
                                <th align="center" scope="col"><?php echo $row['thue'];?></th>
                                <th align="center" scope="col"><?php echo $row['ngayBan'];?></th>
                                <th align="center" scope="col"><?php echo $row['thanhTien'];?></th>
                                <th align="center" scope="col"><?php echo $row['loiNhuan'];?></th>
                            </tr>
                    <?php
                            $i = $i + 1;
                        }
                    } else{
                    ?>
                        <tr class="GridItem" align="center">
                            <th align="center" scope="col" colspan="10">Không có đơn hàng nào.</th>
                        </tr>
                    <?php
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <br/><br/><br/><br/>
        <div class="form_row">
            <h3 style="margin-top: 15px;">Tổng Lợi nhuận tính lại tháng <?php echo date("m/Y");?>: <span id="sumLNTL"><?php echo number_format($this->totalLN, 0, '.', ','); ?></span> đồng</h3>
        </div>
    </div>
</div>

<?php include APPLICATION_PATH . '/modules/default/layouts/scripts/content-outer-end.phtml'; ?>